<?php
namespace app\common\model;

use think\Model;
use fast\Random;

class AppUser extends Model
{
    protected $name = 'app_user';
    protected $autoWriteTimestamp = true;
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    // 生成6位数字推广码
    public static function generatePromotionCode()
    {
        do {
            $code = Random::numeric(6);
        } while (self::where('promotion_code', $code)->find());
        return $code;
    }

    // 验证邀请码是否存在
    public static function checkInviteCode($code)
    {
        return self::where('promotion_code', $code)->value('id');
    }
}